include( 'shared.lua' )


// Clientside only stuff goes here

-- Choose Team Menu --

function set_team()

local frame = vgui.Create( "DFrame" )
frame:SetPos( ScrW() / 2, ScrH() / 2 )
frame:SetSize( 200, 210 )
frame:SetTitle( "Choose Team" )
frame:SetVisible( true )
frame:SetDraggable( false )
frame:ShowCloseButton( true )
frame:MakePopup()

team_1 = vgui.Create( "DButton", frame )
team_1:SetPos( 20, 35 )
team_1:SetSize( 100, 50 )
team_1:SetText( "Citizen" )
team_1.DoClick = function()
	RunConsoleCommand( "team_1" )
end

team_2 = vgui.Create( "DButton", frame )
team_2:SetPos( 20, 105 )
team_2:SetSize( 100, 50 )
team_2:SetText( "Builder" )
team_2.DoClick = function()
	RunConsoleCommand( "team_2" )
end

end
concommand.Add( "t_menu", set_team )

-- Scoreboard Functions --
function scoreboard()
local score = vgui.Create( "DFrame" )
score:SetPos( 50, 50 )
score:SetSize( 500, 700 )
score:SetTitle( "moRP | Scoreboard" )
score:SetVisible( true )
score:SetDraggable( true )
score:ShowCloseButton( true )
score:MakePopup()

local scoreList = vgui.Create( "DListView" )
scoreList:SetParent( score )
scoreList:SetPos( 25, 50 )
scoreList:SetSize( 450, 625 )
scoreList:SetMultiSelect( false )
scoreList:AddColumn( "Username" )
scoreList:AddColumn( "Kills" )

for k,v in pairs(player.GetAll()) do
	scoreList:AddLine(v:Nick(),v:Frags())
end
end
concommand.Add( "show_score", scoreboard )


-- moRP Welcome Menu --

function welcome()
local wmenu = vgui.Create( "DFrame" )
wmenu:SetPos( 10, 20 )
wmenu:SetSize( 1000, 900 )
wmenu:SetTitle( "moRP | Welcome to the Server!" )
wmenu:SetVisible( true )
wmenu:SetDraggable( true )
wmenu:ShowCloseButton( true )
wmenu:MakePopup()

local TestingComboBox = vgui.Create( "DComboBox", wmenu )
TestingComboBox:SetPos( 10, 35 )
TestingComboBox:SetSize( 100, 185 )
TestingComboBox:SetMultiple( false ) -- Don't use this unless you know extensive knowledge about tables
TestingComboBox:AddItem( "Main" ) -- Add our options
TestingComboBox:AddItem( "MOTD" )
 
local MainMenuSheet = vgui.Create( "DPanel", wmenu ) -- We create a panel so we can draw shit on; if we use the frame, it comes up transparent for some reason
MainMenuSheet:SetPos( 125, 50 )
MainMenuSheet:SetSize( DermaFrame:GetWide() - 25, DermaFrame:GetTall() - 25 )
MainMenuSheet.Paint = function()
    if TestingComboBox:GetSelectedItems() and TestingComboBox:GetSelectedItems()[1] then -- make sure something is selected if not we get uber spam of errors
        local OurStringThing = "Your selection is: "..TestingComboBox:GetSelectedItems()[1]:GetValue().."!" -- This was a pain in the ass to figure out; this gets the name of the option chosen
        surface.SetFont( "default" )
        surface.SetTextColor( 255, 255, 255, 255 )
        surface.SetTextPos( 50, 50 )
        surface.DrawText( OurStringThing ) -- Draws the text
    end
end
end

--concommand.Add( "show_welcome", welcome )



-- Draw HUD -

good_hud = { };
 
local function clr( color ) return color.r, color.g, color.b, color.a; end
 
function good_hud:PaintBar( x, y, w, h, colors, value )
 
	self:PaintPanel( x, y, w, h, colors );
 
	x = x + 1; y = y + 1;
	w = w - 2; h = h - 2;
 
	local width = w * math.Clamp( value, 0, 1 );
	local shade = 4;
 
	surface.SetDrawColor( clr( colors.shade ) );
	surface.DrawRect( x, y, width, shade );
 
	surface.SetDrawColor( clr( colors.fill ) );
	surface.DrawRect( x, y + shade, width, h - shade );
 
end
 
function good_hud:PaintPanel( x, y, w, h, colors )
 
	surface.SetDrawColor( clr( colors.border ) );
	surface.DrawOutlinedRect( x, y, w, h );
 
	x = x + 1; y = y + 1;
	w = w - 2; h = h - 2;
 
	surface.SetDrawColor( clr( colors.background ) );
	surface.DrawRect( x, y, w, h );
 
end
 
function good_hud:PaintText( x, y, text, font, colors )
 
	surface.SetFont( font );
 
	surface.SetTextPos( x + 1, y + 1 );
	surface.SetTextColor( clr( colors.shadow ) );
	surface.DrawText( text );
 
	surface.SetTextPos( x, y );
	surface.SetTextColor( clr( colors.text ) );
	surface.DrawText( text );
 
end

function good_hud:TextSize( text, font )
 
	surface.SetFont( font );
	return surface.GetTextSize( text );
 
end

local vars =
{
 
	font = "TargetID",
 
	padding = 10,
	margin = 35,
 
	text_spacing = 2,
	bar_spacing = 5,
 
	bar_height = 16,
 
	width = 0.25
 
};

local colors =
{
 
	background =
	{
 
		border = Color( 190, 255, 128, 255 ),
		background = Color( 120, 240, 0, 75 )
 
	},
 
	text =
	{
 
		shadow = Color( 0, 0, 0, 200 ),
		text = Color( 255, 255, 255, 255 )
 
	},
 
	health_bar =
	{
 
		border = Color( 255, 0, 0, 255 ),
		background = Color( 255, 0, 0, 75 ),
		shade = Color( 255, 104, 104, 255 ),
		fill = Color( 232, 0, 0, 255 )
 
	},
 
	suit_bar =
	{
 
		border = Color( 0, 0, 255, 255 ),
		background = Color( 0, 0, 255, 75 ),
		shade = Color( 136, 136, 255, 255 ),
		fill = Color( 0, 0, 219, 255 )
 
	}
 
};

local function HUDPaint( )
 
	client = client or LocalPlayer( );				-- set a shortcut to the client
	if( !client:Alive( ) ) then return; end				-- don't draw if the client is dead
 
	local _, th = good_hud:TextSize( "TEXT", vars.font );		-- get text size( height in this case )
 
	local i = 2;							-- shortcut to how many items( bars + text ) we have
 
	local width = vars.width * ScrW( );				-- calculate width
	local bar_width = width - ( vars.padding * i );			-- calculate bar width and element height
	local height = ( vars.padding * i ) + ( th * i ) + ( vars.text_spacing * i ) + ( vars.bar_height * i ) + vars.bar_spacing;
 
	local x = vars.margin;						-- get x position of element
	local y = ScrH( ) - vars.margin - height;			-- get y position of element
 
	local cx = x + vars.padding;					-- get x and y of contents
	local cy = y + vars.padding;
 
	good_hud:PaintPanel( x, y, width, height, colors.background );	-- paint the background panel
 
	local by = th + vars.text_spacing;				-- calc text position
 
	local text = string.format( "Health: %iHP", client:Health( ) );	-- get health text
	good_hud:PaintText( cx, cy, text, vars.font, colors.text );	-- paint health text and health bar
	good_hud:PaintBar( cx, cy + by, bar_width, vars.bar_height, colors.health_bar, client:Health( ) / 100 );
 
	by = by + vars.bar_height + vars.bar_spacing;			-- increment text position
 
	local text = string.format( "Suit: %iSP", client:Armor( ) );	-- get suit text
	good_hud:PaintText( cx, cy + by, text, vars.font, colors.text );	-- paint suit text and suit bar
	good_hud:PaintBar( cx, cy + by + th + vars.text_spacing, bar_width, vars.bar_height, colors.suit_bar, client:Armor( ) / 100 );
 
end
hook.Add( "HUDPaint", "PaintOurHud", HUDPaint );

local tohide = { -- This is a table where the keys are the HUD items to hide
	["CHudHealth"] = true,
	["CHudBattery"] = true,
}
local function HUDShouldDraw(name) -- This is a local function because all functions should be local unless another file needs to run it
	if (tohide[name]) then     -- If the HUD name is a key in the table
		return false;      -- Return false.
	end
end
hook.Add("HUDShouldDraw", "HideDefaultHUD", HUDShouldDraw)